<?php namespace App\Model;

//use Illuminate\Database\Eloquent\Model;

class Content extends BaseModel {
    public $timestamps = false;
	//
    public function info()
    {
        return $this->belongsTo('App\Model\WebColumn','column_id');
    }

    public static function getContentByInfoIdAndPageNo($infoId,$pageNo=1,$select=array())
    {
        if(!is_numeric($infoId) || $infoId <= 0 || !is_numeric($pageNo) || $pageNo <= 0){
            return null;
        }
        $selectFiled = self::getSelectField($select);
        $content = self::select($selectFiled)
            ->where('info_id' , '=', $infoId)
            ->where('page_no', '=', $pageNo)
            ->where('is_del', '=', 0)->orderBy('id','desc')->first();

        return $content;
    }

    public static function addContent($content)
    {
        if(empty($content)){
            return false;
        }
        return self::insert($content);
    }
    public static function updateContentByInfoIdAndPageNo($infoId,$pageNo,$content)
    {
        if(!is_numeric($infoId) || $infoId <= 0 || !is_numeric($pageNo) || $pageNo <= 0 || empty($content)){
            return false;
        }
        return self::where('info_id',$infoId)->where('page_no',$pageNo)->update($content);
    }
}
